<template>
  <section>
    <table
      border="0"
      width="100%"
      style="border-spacing: 0;border-collapse: collapse;"
    >
      <tr>
        <td>
          <el-form :model="form" :inline="true">
            <el-form-item>
              <el-select
                v-model="form.status"
                clearable
                placeholder="请选择领用状态"
              >
                <el-option key="-1" value="" label="全部"></el-option>
                <el-option
                  v-for="(value, key) in statusList"
                  :key="key"
                  :value="key"
                  :label="value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="form.applyDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                circle
                icon="el-icon-search"
                @click="getData()"
              ></el-button>
              <el-button type="primary" @click="addApply">药品申领</el-button>
            </el-form-item>
          </el-form>
        </td>
      </tr>
    </table>

    <el-table :data="tableList" border style="width: 100%">
      <el-table-column prop="applyDate" label="申请日期" width="180">
      </el-table-column>
      <el-table-column prop="departmentName" label="领用科室" width="180">
      </el-table-column>
      <el-table-column prop="doctorName" label="领用医生" width="180">
      </el-table-column>
      <el-table-column prop="operatorName" label="经手人"></el-table-column>
      <el-table-column prop="status" label="状态" width="180">
        <template slot-scope="scope">
          {{ scope.row.status | filterStatus(statusList) }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <!-- <el-link @click="onCancel(scope.row)" v-if="scope.row.status == 0"
            >取消申请</el-link
          > -->
          <el-link @click="onDetail(scope.row)" 
            >{{scope.row.status==0?'取消申请':'查看详情'}}</el-link
          >
        </template>
      </el-table-column>
    </el-table>
    <br />
    <el-pagination
      background
      class="drug_pager"
      @current-change="getData"
      layout="prev, pager, next"
      :page-size="pager.pageSize"
      :total="pager.total"
    >
    </el-pagination>
  </section>
</template>
<script>
import enumArr from "./_enum";
export default {
  data() {
    return {
      form: {
        status: "",
        applyDate: "",
      },
      pager: {
        pageNum: 1,
        pageSize:10,
        total: 0,
      },
      statusList: enumArr.status,
      tableList: [],
    };
  },
  mounted() {
    this.getData();
  },
  filters: {
    filterStatus: function(value, list) {
      let str = "";
      for (let key in list) {
        if (key == value) {
          str = list[key];
        }
      }
      return str;
    }
  },
  methods: {
    getData(obj) {
      if(obj){
        this.pager.pageNum=obj;
      }
      let json = Object.assign(this.form, this.pager);
      this.$api.getMedicalDrugApplyLog(json).then((res) => {
        if (res.executed) {
          this.tableList = res.dataBody.list;
          this.pager.total=res.dataBody.total;
        }
      });
    },
    addApply() {
      this.$router.push({
        path: "/page/addReceive",
      });
    },
    onCancel(obj) {
      this.$confirm("您确定要取消申请吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      }).then(() => {
          this.$api.cancelApply({ id: obj.id }).then((res) => {
            if(res.executed){
              this.$message.success(res.message);
              this.getData();
            }else{
              this.$message.success(res.message);
            }
          });
        }).catch(() => {});
    },
    onDetail(obj) {
      let j = {};
      if (obj != null) {
        j = {
          id: this.jiaMi(obj.id)
        };
      } else {
        j = {
          id: this.jiaMi(0)
        };
      }
      let js = this.$utils.JsonToUrl(this.getUrlToken(j));
      this.addNavMenu("申领详情", "/page/cancelDetail?" + js, "");
      this.$router.push({
        path: "/page/cancelDetail",
        query: this.getUrlToken(j),
      });
    },
  },
};
</script>
<style scoped>
.drug_pager {
  text-align: right;
}
</style>
